<?php

/*

    MMetaverse - Open Metaverse Access Library

    Copyright (c) 2009 Mary Jane Soft - Marlon J. Manrique

    http://www.maryjanesoft.com
    http://www.marlonj.com

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
    License as published by the Free Software Foundation; either
    version 2.1 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General
    Public License along with this library; if not, write to the
    Free Software Foundation, Inc., 59 Temple Place, Suite 330,
    Boston, MA  02111-1307  USA

    $Id$

*/

/**
 * @package mjs.mmetaverse.inventory
 */

require_once dirname(__FILE__) . '/../types/MUUID.class.php';

/**
 * A inventory folder
 */
class MFolder {

    /**
     * Folder ID
     *
     * @var MUUID 
     */
    private $id;

    /**
     * Parent ID
     *
     * @var MUUID
     */
    private $parentID;

    /**
     * Folder Name
     *
     * @var string
     */
    private $name;

    /**
     * Default Type 
     *
     * @var integer
     */
    private $defaultType;

    /**
     * Version
     *
     * @var integer
     */
    private $version;

    /**
     * Subfolder
     *
     * @var array
     */
    private $folders;

    /**
     * Create a new folder with the information specified
     *
     * @param MUUID $id
     * @param string $name
     * @param MUUID $parentID
     * @param integer $defaultType
     * @param integer $version
     */
    public function MFolder(MUUID $id, $name, MUUID $parentID, $defaultType, $version) {
        $this->id = $id;
        $this->name = $name;
        $this->parentID = $parentID;
        $this->defaultType = $defaultType;
        $this->version = $version;

        // Init folders info 
        $this->folders = array();
    }

    /**
     * Returns the folder id
     *
     * @return MUUID
     */
    public function getId() {
        return $this->id;
    }

    /**
     * Returns the parent id
     *
     * @return MUUID
     */
    public function getParentID() {
        return $this->parentID;
    }

    /**
     * Return the name
     *
     * @return string
     */
    public function getName() {
        return $this->name;
    }

    /**
     * Returns the default type
     *
     * @return integer
     */
    public function getDefaultType() {
        return $this->defaultType;
    }

    /**
     * Return the version
     *
     * @return integer
     */
    public function getVersion() {
        return $this->version;
    }

    /**
     * Add a subfolder
     *
     * @param MFolder $folder
     */
    public function addFolder(MFolder $folder) {
        $this->folders[] = $folder;
    }

    /**
     * Returns the subfolder with the given name
     *
     * @param string $folderName folder name
     * @return MFolder The folder or null if not available 
     */
    public function getFolderByName($folderName) {
        // Check each folder name 
        foreach($this->folders as $folder) {
            if($folderName == $folder->getName()) {
                return $folder;
            }
        }

        // Folder not found 
        return null;
    }
}

?>